define(["knockout", "durandal/app", "plugins/router", "durandal/events", "durandal/system"],
	function(ko, app, router, Events, system) {
		var obj = {
			name: 'Jack',
			onActivate: function() {
				system.log('my name is ' + this.name);
			}
		}
		var e = {};
		var f = {};
		Events.includeIn(e); //代理events对象
		Events.includeIn(f); //互不干扰
		e.on('activate').then(function() {
			system.log('e.activate');
		})
		//不存在事件继承
		e.on('activate.t1').then(function() {
			system.log('e.activate.t1');
		})
		e.on('activate.t2').then(function() {
			system.log('e.activate.t2');
			system.log('disabled activate');
			this.off('activate');

		}, e);
		//代理基本用不到
//		var p =e.proxy('activate.proxy.cb', obj);
//		e.on('activate.proxy').then(p);
//		e.on('activate.proxy.cb').then(function(args) {
//			system.log('activate.proxy.cb: ' + args);
//		})

		//订阅所有事件触发后触发的事件
		e.on('all').then(function(event) {
			system.log('all: ' + event);
		})
		f.on('activate').then(function() {
			console.log('f.activate');
		})
		
		//----------
		var newCustomer = null;
		app.trigger('customer:new', newCustomer);
		app.on('customer:new').then(function(customer) {
			//do something with the payload
		});
		app.on('all').then(function(event) {
			//the arguments array contains the payload
		});
		var subscription = app.on('customer:new').then(function(customer) {
			//do something with the payload
		});
		subscription.off();
		
		return {
			activate: function() {
				e.trigger('activate activate.t1 activate.t2 activate.proxy',{name:'jane',color:'blue'}); //批量触发事件
				f.trigger('activate');
			},
			all: function() {
				console.log('我会在所有的事件触发后调用')
			}
		};
	})